import { defineConfig } from 'vite'
import { join } from 'path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {
  ElementPlusResolver
} from 'unplugin-vue-components/resolvers'

function resolve(dir) {
  return join(__dirname, dir)
}
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    })
  ],
  resolve: {
    alias: {
      '@': resolve('./src')
    }
  },
  server: {
    //热启动
    hmr: true,
    port: 2000,
    proxy: {
      /* 第一种写法 */
      '^/treasure': {
      	target: 'http://114.132.70.37:8080/',
      	changeOrigin: true, // 允许跨域
      	// rewrite: (path) => path.replace(/^\/app/, ''),
      },

      /* 第二种写法 */
      // '^/geoserver': {
      //   target: 'http://10.10.0.21:8080/',
      //   changeOrigin: true,
      // },

      /* 第三种写法 */
      // '/geoserver': 'http://10.10.0.21:8080/',
    },

  }
})
